package com.xinxin.facelinker.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.easemob.chatuidemo.R;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.xinxin.facelinker.domain.ShowBlacklist;

import java.util.List;

/**
 * Created by gengliang on 2015/8/20.
 */
public class ShowBlacklistAdapter extends BaseAdapter {

    private Context context;
    private List<ShowBlacklist> list;
    private ImageLoader imageLoader;

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    public List<ShowBlacklist> getList() {
        return list;
    }

    public void setList(List<ShowBlacklist> list) {
        this.list = list;
    }

    public ShowBlacklistAdapter(Context context, List<ShowBlacklist> list) {
        this.context = context;
        this.list = list;
        imageLoader= ImageLoader.getInstance();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LinearLayout linearLayout;

        if (convertView != null) {
            linearLayout = (LinearLayout) convertView;
        } else {
            linearLayout = (LinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.layout_show_user, null);
        }

        ShowBlacklist showBlacklist = list.get(position);

        ImageView ivPhoto = (ImageView) linearLayout.findViewById(R.id.ivPhoto);
        TextView tvAccountNum = (TextView) linearLayout.findViewById(R.id.tvAccountNum);
        TextView tvGender = (TextView) linearLayout.findViewById(R.id.tvGender);

        imageLoader.displayImage(showBlacklist.getPhoto_url(), ivPhoto);
        tvAccountNum.setText(showBlacklist.getAccount_num());
        tvGender.setText(showBlacklist.getGender());

        return linearLayout;
    }
}
